<?php
/**
 * Created by PhpStorm.
 * User: dllo
 * Date: 16/8/30
 * Time: 上午9:50
 */
$type = $_POST["type"];
date_default_timezone_set("PRC");
$mysql = mysql_connect("localhost","root","");
$index1 = 0;
$index2 = 0;
if (!$mysql){
    echo '{"err":1,"msg":"数据库连接失败"}';
    // 程序直接退出
    exit();
}
$db = mysql_select_db("0503");
if (!$db){
    echo '{"err":1,"msg":"0503打开失败"}}';
    exit();
}
mysql_query("set names utf8");
switch ($type){
    case "chouJiang":
        $arr = [0,6,9];
        $index= rand(0,2);
        $num = rand(0,100);
        if($num >= 0 && $num < 5){
            $prize = 1;
        }else if($num >= 5 && $num < 10){
            $prize = 2;
        }else if($num >= 10 && $num < 15){
            $prize = 3;
        }else if($num >= 15 && $num < 20){
            $prize = 4;
        }else if($num >= 20 && $num < 25){
            $prize = 5;
        }else if($num >= 25 && $num < 30){
            $prize = 7;
        }else if($num >= 30 && $num < 35){
            $prize = 8;
        }else if($num >= 35 && $num < 40){
            $prize = 10;
        }else if($num >= 45 && $num < 50){
            $prize = 11;
        }else{
            $prize = $arr[$index];
        }
        $arr = array("err"=>0,"prize"=>$prize);
        echo json_encode($arr);
        break;
    case "luzhang":
        $num = $_POST["nums"];
        $sql = "SELECT * FROM carpro WHERE num < $num";
        $result = mysql_query($sql);
        while ($row = mysql_fetch_assoc($result)){
            $index++;
        }
        $sql = "SELECT * FROM carpro";
        $result = mysql_query($sql);
        while ($row = mysql_fetch_assoc($result)){
            $index2++;
        }
        $jibai = $index1/$index2*100;
        $arr = array("err"=>0,"nums"=>$num,"jibai"=>$jibai);
        echo json_encode($arr);
}